<template>
    <el-dialog title="模板设置"  :show-close="false"   :visible.sync="dialogVisible">
        <el-scrollbar style="height: 500px">
            <el-form ref="form" :model="form" label-width="80px">
                <el-form-item label="标题:">
                    <el-input v-model="form.title"></el-input>
                </el-form-item>
                <el-form-item label="备注:">
                    <el-input type="textarea" v-model="form.remark"></el-input>
                </el-form-item>
                <el-form-item label="内容:">
                    <Editor class="editors" ref="editors"></Editor>
                </el-form-item>
            </el-form>
        </el-scrollbar>
        <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible=false">取 消</el-button>
                <el-button type="primary" @click="save()">确 定</el-button>
            </span>
    </el-dialog>
</template>

<script>
    import Editor from "../editor/Editor";
    import descriptionApi from "../../api/descriptionApi";
    export default {
        name: "DescriptionForm",
        components: {Editor},
        data() {
            return {
                form: {
                    id:"",
                    title:"",
                    remark:"",
                    context:"",
                },
                dialogVisible:false
            }
        },
        watch:{
            "form.context":function (val) {
                this.$refs.editors.context=val
            }
        },
        methods:{
            save(){
                this.form.context=this.$refs.editors.context
                if(this.form.id!=""){
                    descriptionApi.update(this.form).then(res=>{
                        this.dialogVisible=false
                        this.$emit("list")
                    })
                }else{
                    descriptionApi.save(this.form).then(res=>{
                        this.dialogVisible=false
                        this.$emit("list")
                    })
                }
            },
            open(id){
                if(id!=""&&id!=null){
                    descriptionApi.get(id).then(res=>{
                        this.form=res.data
                        this.$refs.editors.context=this.form.context
                    })
                }else {
                    this.form={
                        id:"",
                        context: ""
                    }
                }
                this.dialogVisible=true
            }
        }
    }
</script>

<style scoped>

</style>